//  恢复 回收站 日记

const db = require('../db')

// const db = require('../db')
exports.post = (req, res) => {
  const { id, articleid } = req.body
  // console.log(id, articleid)
  const addDelDiarySql = `insert into article select * from delete_article where id="${id}" and articleid="${articleid}"`
  const delArticleSql = `delete from delete_article where id="${id}" and articleid ="${articleid}"`
  // 将回收站的数据表  => 添加到 用户日记数据表
  db.query(addDelDiarySql, (err, data) => {
    if (err) return console.log('addDelDiarySql错误' + err.sqlMessage)
    if (data.affectedRows === 1) {
      // 将回收站的数据表  => 删除
      db.query(delArticleSql, (err, data) => {
        if (err) return console.log('delArticleSql语句错误' + err)
        if (data.affectedRows === 1) {
          return res.send({
            status: 201,
            message: '恢复日记成功'
          })
        }
      })
    } else {
      return res.send({
        status: 401,
        message: '恢复日记失败'
      })
    }
  })
}
